package com.ihg.hiex.admin.dao.session;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Execute;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.ihg.hiex.entity.session.Session;
import com.ihg.hiex.entity.session.during.SessionInBasket;
import com.ihg.hiex.entity.session.during.SessionInBasketAnswer;
import com.ihg.hiex.entity.session.during.SessionInBasketAnswerStatus;
import com.ihg.hiex.entity.user.Assessor;
import com.ihg.hiex.entity.user.Delegate;

/**
 * 
 * @author dan
 *
 */
@Dao("hibernate")
public interface SessionInbasketDao {
    
    /**
     * 
     * @param session
     * @param name
     * @return
     */
    @Query("FROM SessionInBasket WHERE disabled = false AND session = :session AND name = :name")
    public List<SessionInBasket> list(@Variable("session") Session session, @Variable("name") String name);
    
    /**
     * 
     * @param session
     * @param assessor
     * @param delegate
     * @param name
     * @return
     */
    @Query("FROM SessionInBasket WHERE disabled = false AND session = :session AND assessor = :assessor AND delegate = :delegate AND name = :name")
    public SessionInBasket load(@Variable("session") Session session, @Variable("assessor") Assessor assessor, @Variable("delegate") Delegate delegate, @Variable("name") String name);

    /**
     * 
     * @param session
     * @param delegate
     * @return
     */
    @Query("FROM SessionInBasket WHERE disabled = false AND session = :session AND delegate = :delegate")
    public SessionInBasket load(@Variable("session") Session session, @Variable("delegate") Delegate delegate);
    
    /**
     * 
     * @param sessionInBasket
     * @param name
     * @return
     */
    @Query("FROM SessionInBasketAnswer WHERE disabled = false AND sessionInBasket = :sessionInBasket AND name = :name")
    public List<SessionInBasketAnswer> listAnswer(@Variable("sessionInBasket") SessionInBasket sessionInBasket, @Variable("name") String name);

    /**
     * 
     * @param sessionInBaskets
     * @return
     */
    @Query("FROM SessionInBasketAnswer WHERE disabled = false AND sessionInBasket in(:sessionInBaskets)")
    public List<SessionInBasketAnswer> listAnswer(@Variable("sessionInBaskets") List<SessionInBasket> sessionInBaskets);
    
    /**
     * 
     * @param sessionInBasket
     * @return
     */
    @Query("FROM SessionInBasketAnswer WHERE disabled = false AND sessionInBasket = :sessionInBasket")
    public List<SessionInBasketAnswer> listAnswer(@Variable("sessionInBasket") SessionInBasket sessionInBasket);

    /**
     * 
     * @param status
     * @param sessionInBasket
     * @param name
     */
    @Execute("UPDATE SessionInBasketAnswer SET status = :status WHERE disabled = false AND sessionInBasket = :sessionInBasket AND name = :name")
    public void submitAnswer(@Variable("status") SessionInBasketAnswerStatus status, @Variable("sessionInBasket") SessionInBasket sessionInBasket, @Variable("name") String name);
}
